/* label.h */

#ifndef DODO_LABEL_H
#define DODO_LABEL_H

#include <dodo_plot/kernel/plotfwd.h>
#include <dodo_plot/kernel/basic_elements.h>
#include <string>
#include <sstream>
#include <cairomm/cairomm.h>

namespace dodo_plot
{
/**
 * 文本标签.
 * 可设置字体, 字体大小, 
 * 对齐方式{LEFT, CENTER, RIGHT},
 * 文本颜色, 背景颜色, 边框颜色.
 *
 * 在与其他Picture组合时, 标签按大小为0处理.
 */
/// 文本标签
class Label
{
public:
	void draw(const Plotter& plotter) const;
	//extra draw method for convinience.
	void draw(Context_p cr, const Point& p) const;
public:
	double height() const { return 0;}
	double width() const { return 0;}
	Position local_pos() const { return Position(0, 0, 0, 0); }
public:
	std::string text() const;
	
	std::string set_text(const std::string& new_text);
	
	template<class T>
	std::string set_text(const T& new_text);

	std::string append(const std::string& extra_text);
	std::string append(const Label& l);

	Color set_color(const Color& new_color);
	Color set_border_color(const Color& new_border_color);
	Color set_fill_color(const Color& new_fill_color);
	
	Font set_font(const Font& new_font);
	double set_font_size(double new_font_size);
	int set_align_mode(int new_align_mode);

	
public:
	Label(const std::string& text = "", 
		double font_size = 12, 
		int align_mode = CENTER, 
		const Color& color = color_name::BLACK, 
		const Color& border_color = color_name::TRANSPARENT,
		const Color& fill_color = color_name::TRANSPARENT,
		const Font& font = FONT_DEFAULT);
	template<class T>
	Label(const T& text,
		double font_size = 12, 
		int align_mode = CENTER, 
		const Color& color = color_name::BLACK, 
		const Color& border_color = color_name::TRANSPARENT,
		const Color& fill_color = color_name::TRANSPARENT,
		const Font& font = FONT_DEFAULT);
		
private:
	std::string text_;
	double font_size_;
	mutable Font font_;
	Color color_;
	Color border_color_;
	Color fill_color_;
	int align_mode_;
	//TODO: add rotate angle
};

template <class T>
Label::Label(const T& text,
	double font_size,
	int align_mode,
	const Color& color,
	const Color& border_color,
	const Color& fill_color,
	const Font& font
	) :
	font_size_(font_size),
	align_mode_(CENTER), //set to default first, then change it.
	color_(color),
	fill_color_(fill_color),
	border_color_(border_color),
	font_(font)
{
	set_align_mode(align_mode);
	
	std::stringstream ss;
	ss << text;
	text_ = ss.str();
}

template<class T>
std::string Label::set_text(const T& new_text)
{
	std::string old = text_;
	std::stringstream ss;
	ss << new_text;
	text_ = ss.str();
	return old;
}

}

#endif //DODO_LABEL_H

